home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
toda
/
trans
/
src
/
tr_sub.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
71KB
|
2,712 lines
/*
Trans Command 1990 6/8
1993 3/6 修正
*/
#include <stdlib.h>
#include <math.h>
#include <egb.h>
#include <mos.h>
#include "egb17int.h"
extern error_check( int n );
extern square_check( int a[][2] );
extern backupput();
extern mouse( int para[], int xd, int yd, int mode );
extern mousesub2( int x, int y );
extern spuit( int col[] );
extern mask_on(int mode);
extern mask_rev(int mode);
extern command_start();
extern command_end(char *buffer);
extern lens_set( int mul );
extern lens_rest( int mul );
extern polygon1( int para[], char *buffer );
extern polygon2( char *buffer );
extern box( int para[], char *buffer );
extern gprint( char *dsp, int x, int y );
extern gprint2( char *dsp, int x, int y );
extern itochar( int number, int x, char *dsp );
extern windget();
extern windput();
extern vpoly1();
extern vsync_wait( int ) ;
#define C_COLOR 0x7fff
#define OFF_COLOR 0x4a52 /* g18 r18 b18 */
paint(col,pvar,ework,gwork,bbuf,mbuf)
int col[],pvar[];
char *ework,*gwork,*bbuf,*mbuf;
{
int color,min,max,i,j,wt,jiscode,maskmode,sw,cx,cy;
int data[13];
char dsp1[] = "<<PAINT>> B R G spuit MASK( ) MIX LENS EXIT";
char dsp2[] = "LINE(size mix mode ) POLY □ ○ (jis dot ) GRAD PAINT";
char dsp[13]; /* for jis code display */
int mp[4]; /* mouse para */
command_start(); /* 全画面保存 & data clear */
maskmode = 0;
paint1: windget();
gprint( dsp1, 0, 463 );
gprint( dsp2, 0, 479 );
for( i = 0 ; i < 13 ; i++ )data[i] = -1;
paint_dsp(data,pvar,col,ework);
paintA: color = col[1] +(col[2]<<5) +(col[3]<<10); /* palette */
EGB_color( ework,0, color );
gprint( "■", 216, 463 );
EGB_color( ework, 0, OFF_COLOR ); /* mask mode display */
gprint( "on rev off", 280, 463 );
EGB_color( ework, 0, C_COLOR );
switch( maskmode ){
case 0: gprint( "off", 280+56, 463 );
break;
case 1: gprint( "on", 280, 463 );
break;
case 2: gprint( "rev", 280+24, 463 );
break;
}
jiscode = pvar[8]*0x1000 + pvar[9]*0x0100 + pvar[10]*0x0010 + pvar[11];
gprint2( " ", 288, 479 ); /* jis code */
WORD( dsp + 0 ) = 288;
WORD( dsp + 2 ) = 479;
WORD( dsp + 4 ) = 1;
DWORD( dsp + 6 ) = jiscode;
EGB_jisString( ework, dsp );
paint2: MOS_disp(1);
mouse( mp, 0, 0, 1);
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( cy < 447 )goto paint2;
if( cy < 463 ){
if( cx < 72 )goto paint2;
if( cx < 108 ){ /* B */
i = 0; min = 0; max = 31;
goto paint7;
}
if( cx < 140 ){ /* R */
i = 1; min = 0; max = 31;
goto paint7;
}
if( cx < 172 ){ /* G */
i = 2; min = 0; max = 31;
goto paint7;
}
if( cx < 240 ){ /* spuit 0 */
j = 0;
goto paint3;
}
if( cx < 300 ){ /* MASK 1 */
j = 1;
goto paint3;
}
if( cx < 332 ){ /* mask rev 2 */
j = 2;
goto paint3;
}
if( cx < 372 ){ /* mask off 3 */
j = 3;
goto paint3;
}
if( cx < 428 ){ /* mix */
i = 3; min = 0; max = 256;
goto paint7;
}
if( cx < 472 ){ /* lens */
i = 4; min = 1; max = 8;
goto paint7;
}
if( cx < 512 ){ /* exit 4 */
j = 4;
goto paint3;
}
goto paint2;
}
if( cy < 480 ){
if( cx < 36 ){ /* line 5 */
j = 5;
goto paint3;
}
if( cx < 84 ){ /* line size */
i = 5; min = 1; max = 3;
goto paint7;
}
if( cx < 140 ){ /* line mix */
i = 6; min = 0; max = 257;
goto paint7;
}
if( cx < 196 ){ /* line mode */
i = 7; min = 0; max = 1;
goto paint7;
}
if( cx < 236 ){ /* polygon 6 */
j = 6;
goto paint3;
}
if( cx < 260 ){ /* rectangle 7 */
j = 7;
goto paint3;
}
if( cx < 284 ){ /* circle 8 */
j = 8;
goto paint3;
}
if( cx < 312 ){ /* put 9 */
j = 9;
goto paint3;
}
if( cx < 344 ){ /* put data */
i = 8; min = 0x2; max = 0x4;
goto paint7;
}
if( cx < 352 ){ /* put data */
i = 9; min = 0x0; max = 0xf;
goto paint7;
}
if( cx < 360 ){ /* put data */
i = 10; min = 0x0; max = 0xf;
goto paint7;
}
if( cx < 372 ){ /* put data */
i = 11; min = 0x0; max = 0xf;
goto paint7;
}
if( cx < 428 ){ /* put dot */
i = 12; min = 1; max = 32;
goto paint7;
}
if( cx < 468 ){ /* grad 10 */
j = 10;
goto paint3;
}
if( cx < 512 ){ /* PAINT 11 */
j = 11;
goto paint3;
}
goto paint2;
}
goto paint2;
paint3: mouse( mp, 0, 0, 0);
if( sw > 1 )goto paint2;
MOS_disp(0);
windput();
switch( j ){
case 0: lens_set( pvar[4] );
spuit(col); /* spuit */
lens_rest( pvar[4] );
break;
case 1: mask_on(1); /* mask on */
maskmode = 1;
break;
case 2: mask_rev(1); /* mask rev */
maskmode = 2;
break;
case 3: vpoly1(); /* v-ram clear (mask off) */
maskmode = 0;
break;
case 4: command_end(bbuf); /* exit */
return 0;
case 5: lens_set( pvar[4] ); /* line */
line( col, pvar[5], pvar[6], pvar[7], gwork );
lens_rest( pvar[4] );
break;
case 6: lens_set( pvar[4] ); /* polygon */
polygon_paint( col, pvar[3], gwork, bbuf );
lens_rest( pvar[4] );
break;
case 7: lens_set( pvar[4] ); /* rectangle */
rectangle( col, pvar[3], maskmode, ework, mbuf );
lens_rest( pvar[4] );
break;
case 8: lens_set( pvar[4] ); /* circle */
circle( col, pvar[3], maskmode, ework, mbuf );
lens_rest( pvar[4] );
break;
case 9: lens_set( pvar[4] ); /* put */
put_string( col, jiscode, pvar[12], pvar[3], maskmode, ework, mbuf );
lens_rest( pvar[4] );
break;
case 10: lens_set( pvar[4] ); /* grad */
gradation( pvar[3], gwork, ework );
lens_rest( pvar[4] );
break;
case 11: lens_set( pvar[4] ); /* PAINT */
paint2( col, pvar[3], maskmode, ework, mbuf );
lens_rest( pvar[4] );
break;
}
goto paint1;
paint7: wt = 20;
pvar[0] = col[1];
pvar[1] = col[2];
pvar[2] = col[3];
paint8: if( sw == 1 )pvar[i] = pvar[i] + 1;
if( sw == 2 )pvar[i] = pvar[i] - 1;
if( pvar[i] < min )pvar[i] = max;
if( pvar[i] > max )pvar[i] = min;
col[1] = pvar[0];
col[2] = pvar[1];
col[3] = pvar[2];
paint_dsp(data,pvar,col,ework);
vsync_wait( wt );
wt = 2;
MOS_rdpos(&sw,&cx,&cy);
if( sw > 0 )goto paint8;
goto paintA;
}
paint_dsp(data,pvar,col,ework)
int data[],pvar[],col[];
char *ework;
{
int i, x, y;
int point[13][3] = { { 88,463,2 }, /* color data */
{ 120,463,2 },
{ 152,463,2 },
{ 400,463,3 }, /* mix */
{ 464,463,1 }, /* lens */
{ 72,479,1 }, /* line */
{ 112,479,3 },
{ 176,479,1 },
{ 336,479,1 }, /* jis code */
{ 344,479,1 }, /* jis code */
{ 352,479,1 }, /* jis code */
{ 360,479,1 }, /* jis code */
{ 400,479,2 } /* dot */
};
char dsp[10];
pvar[0] = col[1];
pvar[1] = col[2];
pvar[2] = col[3];
col[0] = col[1] + (col[2] << 5) + (col[3] << 10);
EGB_color(ework,0,C_COLOR);
for( i = 0 ; i < 13 ; i++ ){
if( data[i] != pvar[i] ){
x = point[i][0]; y = point[i][1];
MOS_disp(0);
itochar( pvar[i], point[i][2], dsp );
if( i==6 && pvar[i]==257 )gprint2( "NOR", x, y );
else gprint2( dsp, x, y );
data[i] = pvar[i];
}
}
return 0;
}
line( col, size, half, mode, gwork )
int col[],size,half,mode;
char *gwork;
{
int i, sw, cx, cy, mp[4];
int para[16];
unsigned int add;
line1: MOS_disp(1);
mouse( mp, 0, 0, 1);
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 ){
mouse( mp, 0, 0, 0 );
if( spuit(col) )return 0;
goto line1;
}
para[0] = cx;
para[1] = cy;
para[2] = cx;
para[3] = cy;
para[4] = col[0];
para[5] = size;
para[6] = half;
para[7] = 0x10c;
line17( gwork, para );
line2: add = (unsigned int)( (cx << 1) + (cy << 10) );
if( add > 524286 )add = 524286;
xorw( add, 0x10c, 0x7fff );
do{
if( mode == 0 ){
MOS_rdpos(&sw,&cx,&cy);
mousesub2( cx, cy );
if( sw != 1 ){
xorw( add, 0x10c, 0x7fff );
goto line1;
}
}
if( mode != 0 ){
mouse( mp, 0, 0, 3 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw != 1 ){
xorw( add, 0x10c, 0x7fff );
mouse( mp, 0, 0, 0 );
goto line1;
}
}
}while( (para[0] == cx) && (para[1] == cy) );
xorw( add, 0x10c, 0x7fff );
para[2] = cx;
para[3] = cy;
line17( gwork, para );
for( i=0 ; i<300 ; i++ ); /* wait */
para[0] = para[2];
para[1] = para[3];
goto line2;
}
paint2( col, mix, maskmode, ework, mbuf )
int col[],mix,maskmode;
char *ework,*mbuf;
{
int sw, cx, cy, mp[4];
short int para[8];
EGB_maskRegion(ework,mbuf); /* mask buffer set */
paint1: EGB_mask(ework,0);
MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 ){
EGB_mask(ework,0); /* mask rest */
if( spuit(col) )return 0;
goto paint1;
}
para[0] = cx; para[1] = cy;
if( maskmode == 1 )EGB_mask(ework,0x80);
if( maskmode == 2 )EGB_mask(ework,0x81);
EGB_paintMode(ework,0x22); /* べた塗り */
EGB_writeMode(ework,7); /* pastel */
EGB_pastel(ework,mix); /* mix rate */
EGB_color(ework,0,col[0]); /* color */
EGB_color(ework,2,col[0]); /* color */
EGB_closePaint( ework, (char *)para );
goto paint1;
}
polygon_paint( col, mix, gwork, bbuf )
int col[], mix;
char *gwork, *bbuf;
{
int mp[4], pp[6];
int para[16];
poly1: if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0);
if( spuit(col) )return 0;
goto poly1;
}
polygon2(bbuf);
para[0] = ( unsigned int )bbuf;
para[1] = 0x10c;
para[2] = pp[1];
para[3] = pp[2];
para[4] = pp[3];
para[5] = pp[4];
para[6] = col[0];
para[7] = mix;
polypaint( gwork, para );
goto poly1;
}
rectangle( col, mix, maskmode, ework, mbuf )
int col[],mix,maskmode;
char *ework,*mbuf;
{
int sw, cx, cy, mp[4];
short int para[8];
EGB_maskRegion(ework,mbuf); /* mask buffer set */
rect1: EGB_mask(ework,0);
MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 ){
EGB_mask(ework,0); /* mask rest */
if( spuit(col) )return 0;
goto rect1;
}
para[0] = cx; para[1] = cy;
mouse( mp, 0, 0, 4 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 )goto rect1;
para[2] = cx; para[3] = cy;
if( maskmode == 1 )EGB_mask(ework,0x80);
if( maskmode == 2 )EGB_mask(ework,0x81);
EGB_paintMode(ework,0x22); /* べた塗り */
EGB_writeMode(ework,7); /* pastel */
EGB_pastel(ework,mix); /* mix rate */
EGB_color(ework,0,col[0]); /* color */
EGB_color(ework,2,col[0]); /* color */
EGB_rectangle( ework, (char *)para );
goto rect1;
}
circle( col, mix, maskmode, ework, mbuf )
int col[],mix,maskmode;
char *ework,*mbuf;
{
int sw, cx, cy, mp[4];
short int para[8];
EGB_maskRegion(ework,mbuf); /* mask buffer set */
circ1: EGB_mask(ework,0);
MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 ){
EGB_mask(ework,0); /* mask rest */
if( spuit(col) )return 0;
goto circ1;
}
para[0] = cx; para[1] = cy;
mouse( mp, 0, 0, 12 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 )goto circ1;
para[2] = cx-para[0]; para[3] = cy-para[1];
if( para[2] < 0 )para[2] = -para[2];
if( para[3] < 0 )para[3] = -para[3];
if( maskmode == 1 )EGB_mask(ework,0x80);
if( maskmode == 2 )EGB_mask(ework,0x81);
EGB_paintMode(ework,0x22); /* べた塗り */
EGB_writeMode(ework,7); /* pastel */
EGB_pastel(ework,mix); /* mix rate */
EGB_color(ework,0,col[0]); /* color */
EGB_color(ework,2,col[0]); /* color */
EGB_ellipse( ework, (char *)para );
goto circ1;
}
put_string( col, string, dot, mix, maskmode, ework, mbuf )
int col[], string, dot, mix, maskmode;
char *ework, *mbuf;
{
int x0=-1, y0=-1, sw, cx, cy, mp[4];
char dsp[12];
unsigned int add;
EGB_maskRegion(ework,mbuf); /* mask buffer set */
EGB_mask(ework,0); /* mask rest */
EGB_textZoom( ework, 1, dot, dot ); /* 拡大率 */
WORD(dsp+4) = 1; /* 1文字 */
DWORD(dsp+6) = string; /* string set */
put01: MOS_disp(1);
mouse( mp, 0, 0, 1);
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1){
mouse( mp, 0, 0, 0);
if( spuit(col) )return 0;
}
EGB_paintMode(ework,0x22); /* べた塗り */
EGB_pastel(ework,mix); /* mix rate */
EGB_writeMode(ework,7); /* pastel */
EGB_color(ework,0,col[0]); /* color */
EGB_color(ework,2,col[0]); /* color */
if( maskmode == 1 )EGB_mask(ework,0x80);
if( maskmode == 2 )EGB_mask(ework,0x81);
put02: add = (unsigned int)( (cx << 1) + (cy << 10) );
if( add > 524286 )add = 524286;
xorw( add, 0x10c, 0x7fff );
do{
MOS_rdpos(&sw,&cx,&cy);
mousesub2( cx, cy );
if( sw != 1 ){
xorw( add, 0x10c, 0x7fff );
EGB_mask(ework,0); /* mask rest */
goto put01;
}
}while( cx == x0 && cy == y0 );
xorw( add, 0x10c, 0x7fff );
if( dot > 1 )WORD(dsp+0) = cx - ( dot >> 1 ) + 1; /* put */
else WORD(dsp+0) = cx;
WORD(dsp+2) = cy+( dot >> 1 );
EGB_jisString(ework,dsp);
x0 = cx; y0 = cy;
goto put02;
}
gradation( mix, gwork, ework )
int mix;
char *gwork, *ework;
{
int i, bn, xmin, ymin, xmax, ymax, det, axm, aym;
int bx0, by0, bx1, by1, bx2, by2, bx3, by3;
int sw, cx, cy;
int b[5][2], para[20], mp[4];
EGB_color(ework,0,C_COLOR);
EGB_paintMode(ework,0x2);
EGB_writeMode(ework,4);
grad01: MOS_disp(1);
mouse( mp, 0, 0, 0);
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 )return 0;
bn = 0; b[0][0] = cx; b[0][1] = cy;
while( bn < 3 ){
mouse( mp, 0, 0, 2);
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 ){
if( bn == 0 )goto grad01;
for( i=1 ; i<=bn ; i++ ){ /* やりなおし */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
goto grad01;
}
bn++; b[bn][0] = cx; b[bn][1] = cy; /* 次のステップ */
line_set( b[bn-1][0], b[bn-1][1], b[bn][0], b[bn][1], ework );
}
bn = 4; b[4][0] = b[0][0]; b[4][1] = b[0][1]; /* 最後のライン */
line_set( b[3][0], b[3][1], b[4][0], b[4][1], ework );
for( i=1 ; i<=bn ; i++ ){ /* ライン消し */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
if( error_check( square_check( b ) ) )goto grad01;
xmin = b[0][0]; xmax = b[0][0]; ymin = b[0][1]; ymax = b[0][1];
for( i=0 ; i<4 ; i++ ){ /* 最大,最小 */
if( xmin > b[i][0] )xmin = b[i][0];
if( xmax < b[i][0] )xmax = b[i][0];
if( ymin > b[i][1] )ymin = b[i][1];
if( ymax < b[i][1] )ymax = b[i][1];
}
bx0 = b[0][0]; by0 = b[0][1]; /* ベクトル */
bx1 = b[1][0] - bx0; by1 = b[1][1] - by0;
bx2 = b[2][0] - bx0; by2 = b[2][1] - by0;
bx3 = b[3][0] - bx0; by3 = b[3][1] - by0;
det = bx1*by3 - bx3*by1; /* DET */
if( det == 0 )goto grad01;
para[2] = ( by3*65536 )/det; para[3] = -( bx3*65536 )/det;
para[4] = -( by1*65536 )/det; para[5] = ( bx1*65536 )/det;
axm = para[2]*bx2 + para[3]*by2;
aym = para[4]*bx2 + para[5]*by2;
if( axm*aym == 0 )goto grad01;
para[6] = ( (double)axm - 65536 )/( (double)aym )*65536;
para[7] = ( (double)aym - 65536 )/( (double)axm )*65536;
para[8] = bx0; para[9] = by0;
para[10] = xmin; para[11] = ymin; para[12] = xmax; para[13] = ymax;
para[14] = ( peekw( b[0][1]*1024+b[0][0]*2 ,0x10c ) & 0x7fff );
para[15] = ( peekw( b[1][1]*1024+b[1][0]*2 ,0x10c ) & 0x7fff );
para[16] = ( peekw( b[3][1]*1024+b[3][0]*2 ,0x10c ) & 0x7fff );
para[17] = ( peekw( b[2][1]*1024+b[2][0]*2 ,0x10c ) & 0x7fff );
para[18] = mix;
para[0] = 0; /* dummy */
para[1] = 0x10c; /* VRAM segment */
MOS_disp(0);
grad17( gwork, para );
goto grad01;
}
color_change(col1,col2,cvar,ework,gwork,bbuf)
int col1[], col2[], cvar[];
char *ework, *gwork, *bbuf;
{
int color1,color2,min,max,i,j,wt,maskmode,sw,cx,cy;
int data[10];
char dsp1[] = "<<COLOR-CHANGE>> EXG( , ) MASK( ) CANCEL LENS EXIT";
char dsp2[] = "CNV(mode B R G spuit → spuit B R G ) MONO NEGA";
int mp[4];
command_start(); /* 全画面保存 & data clear */
maskmode = 0;
color1: windget();
gprint( dsp1, 0, 463 );
gprint( dsp2, 0, 479 );
for( i = 0 ; i < 10 ; i++ )data[i] = -1;
color_dsp(cvar,data,col1,col2,ework);
colorA: color1 = col1[1] +(col1[2]<<5) +(col1[3]<<10); /* palette */
EGB_color( ework,0, color1 );
gprint( "■", 216, 479 );
color2 = col2[1] +(col2[2]<<5) +(col2[3]<<10); /* palette */
EGB_color( ework,0, color2 );
gprint( "■", 248, 479 );
EGB_color( ework, 0, OFF_COLOR ); /* mask mode display */
gprint( "on rev off", 256, 463 );
EGB_color( ework, 0, C_COLOR );
switch( maskmode ){
case 0: gprint( "off", 256+56, 463 );
break;
case 1: gprint( "on", 256, 463 );
break;
case 2: gprint( "rev", 256+24, 463 );
break;
}
color2: MOS_disp(1);
mouse( mp, 0, 0, 1);
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( cy < 447 )goto color2;
if( cy < 463 ){
if( cx < 132 )goto color2; /* nothing */
if( cx < 164 ){ /* exg 10 */
j = 10;
goto color3;
}
if( cx < 180 ){ /* exg color 1 */
i = 8; min = 0; max = 2;
goto color7;
}
if( cx < 208 ){ /* exg color 2 */
i = 9; min = 0; max = 2;
goto color7;
}
if( cx < 276 ){ /* MASK on 0 */
j = 0;
goto color3;
}
if( cx < 308 ){ /* MASK rev 1 */
j = 1;
goto color3;
}
if( cx < 352 ){ /* mask off 2 */
j = 2;
goto color3;
}
if( cx < 416 ){ /* cancel 3 */
j = 3;
goto color3;
}
if( cx < 468 ){ /* lens */
i = 0; min = 1; max = 8;
goto color7;
}
if( cx < 512 ){ /* exit 4 */
j = 4;
goto color3;
}
goto color2;
}
if( cy < 480 ){
if( cx < 28 ){ /* cnv 5 */
j = 5;
goto color3;
}
if( cx < 76 ){ /* mode */
i = 1; min = 0; max = 3;
goto color7;
}
if( cx < 108 ){ /* B1 */
i = 2; min = 0; max = 31;
goto color7;
}
if( cx < 140 ){ /* R1 */
i = 3; min = 0; max = 31;
goto color7;
}
if( cx < 172 ){ /* G1 */
i = 4; min = 0; max = 31;
goto color7;
}
if( cx < 240 ){ /* spuit1 6 */
j = 6;
goto color3;
}
if( cx < 308 ){ /* spuit1 7 */
j = 7;
goto color3;
}
if( cx < 340 ){ /* B2 */
i = 5; min = 0; max = 31;
goto color7;
}
if( cx < 372 ){ /* R2 */
i = 6; min = 0; max = 31;
goto color7;
}
if( cx < 416 ){ /* G2 */
i = 7; min = 0; max = 31;
goto color7;
}
if( cx < 464 ){ /* mono 8 */
j = 8;
goto color3;
}
if( cx < 512 ){ /* nega 9 */
j = 9;
goto color3;
}
goto color2;
}
goto color2;
color3: mouse( mp, 0, 0, 0);
if( sw > 1 )goto color2;
MOS_disp(0);
windput();
switch( j ){
case 0: mask_on(1); /* mask on */
maskmode = 1;
break;
case 1: mask_rev(1); /* mask rev */
maskmode = 2;
break;
case 2: vpoly1(); /* v-ram clear (mask off) */
maskmode = 0;
break;
case 3: backupput(); /* cancel */
if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
break;
case 4: command_end(bbuf); /* exit */
return 0;
case 5: lens_set( cvar[0] ); /* cnv */
color_cnv( cvar[1], col1, col2, gwork, bbuf );
lens_rest( cvar[0] );
break;
case 6: lens_set( cvar[0] );
spuit(col1); /* spuit1 */
lens_rest( cvar[0] );
break;
case 7: lens_set( cvar[0] );
spuit(col2); /* spuit2 */
lens_rest( cvar[0] );
break;
case 8: lens_set( cvar[0] ); /* mono */
color_mono( gwork, bbuf );
lens_rest( cvar[0] );
break;
case 9: lens_set( cvar[0] ); /* nega */
color_nega( gwork, bbuf );
lens_rest( cvar[0] );
break;
case 10: lens_set( cvar[0] ); /* exg */
color_exg( cvar[8], cvar[9], gwork, bbuf );
lens_rest( cvar[0] );
break;
}
goto color1;
color7: wt = 20;
cvar[2] = col1[1];
cvar[3] = col1[2];
cvar[4] = col1[3];
cvar[5] = col2[1];
cvar[6] = col2[2];
cvar[7] = col2[3];
color8: if( sw == 1 )cvar[i] = cvar[i] + 1;
if( sw == 2 )cvar[i] = cvar[i] - 1;
if( cvar[i] < min )cvar[i] = max;
if( cvar[i] > max )cvar[i] = min;
col1[1] = cvar[2];
col1[2] = cvar[3];
col1[3] = cvar[4];
col2[1] = cvar[5];
col2[2] = cvar[6];
col2[3] = cvar[7];
color_dsp(cvar,data,col1,col2,ework);
vsync_wait( wt );
wt = 2;
MOS_rdpos(&sw,&cx,&cy);
if( sw > 0 )goto color8;
goto colorA;
}
color_dsp(cvar,data,col1,col2,ework)
int cvar[], data[], col1[], col2[];
char *ework;
{
int i, x, y;
int point[][3] = { { 456,463,1 }, /* lens */
{ 64,479,1 }, /* mode */
{ 88,479,2 }, /* color data1 */
{ 120,479,2 },
{ 152,479,2 },
{ 320,479,2 }, /* color data2 */
{ 352,479,2 },
{ 384,479,2 },
{ 168,463,1 }, /* exg color */
{ 184,463,1 }
};
char dsp[10];
cvar[2] = col1[1];
cvar[3] = col1[2];
cvar[4] = col1[3];
cvar[5] = col2[1];
cvar[6] = col2[2];
cvar[7] = col2[3];
col1[0] = col1[1] + (col1[2] << 5) + (col1[3] << 10);
col2[0] = col2[1] + (col2[2] << 5) + (col2[3] << 10);
EGB_color(ework,0,C_COLOR);
for( i = 0 ; i < 10 ; i++ ){
if( data[i] != cvar[i] ){
x = point[i][0]; y = point[i][1];
MOS_disp(0);
if( i < 8 )itochar( cvar[i], point[i][2], dsp );
if( i >= 8 ){
dsp[1] = (char)0;
if( cvar[i] == 0 )dsp[0] = 'B';
if( cvar[i] == 1 )dsp[0] = 'R';
if( cvar[i] == 2 )dsp[0] = 'G';
}
gprint2( dsp, x, y );
data[i] = cvar[i];
}
}
return 0;
}
color_cnv( mode, col1, col2, gwork, bbuf )
int mode, col1[], col2[];
char *gwork, *bbuf;
{
int i, j, n;
double as01, as02, as11, det;
double v0[4][4], v1[4][4], a[4][4], m[10];
int mp[4], pp[6], para[20];
if( mode == 2 ){
for( i=0 ; i<=8 ; i++ )para[i+2] = 0;
para[2] = 65536; para[6] = 65536; para[10] = 65536;
for( i=0 ; i<=2 ; i++ )para[i+11] = (col2[i+1] - col1[i+1])*65536;
goto cnv03;
}
if( mode == 3 ){
for( i=0 ; i<=8 ; i++ )para[i+2] = 0;
para[2] = 65536*col2[1];if( col1[1] )para[2] = para[2]/col1[1];
para[6] = 65536*col2[2];if( col1[2] )para[6] = para[6]/col1[2];
para[10]= 65536*col2[3];if( col1[3] )para[10]=para[10]/col1[3];
for( i=0 ; i<=2 ; i++ )para[i+11] = 0;
goto cnv03;
}
as01 = sqrt( col1[1]*col1[1] + col1[2]*col1[2] + col1[3]*col1[3] );
as11 = sqrt( col2[1]*col2[1] + col2[2]*col2[2] + col2[3]*col2[3] );
for( i=1 ; i<=3 ; i++ ){
if( as01 > 0 ){
v0[i][1] = col1[i]/as01;
}
else v0[i][1] = 0;
if( as11 > 0 ){
v1[i][1] = col2[i]/as11;
}
else v1[i][1] = 0;
}
v0[1][2] = v0[2][1]*v1[3][1] - v0[3][1]*v1[2][1];
v0[2][2] = v0[3][1]*v1[1][1] - v0[1][1]*v1[3][1];
v0[3][2] = v0[1][1]*v1[2][1] - v0[2][1]*v1[1][1];
as02=sqrt( v0[1][2]*v0[1][2] + v0[2][2]*v0[2][2] + v0[3][2]*v0[3][2] );
if( as02 == 0 ){
for( i=0 ; i<=8 ; i++ )m[i] = 0;
m[0] = 1; m[4] = 1; m[8] = 1;
goto cnv02;
}
for( i=1 ; i<=3 ; i++ ){
v0[i][2] = v0[i][2]/as02;
v1[i][2] = v0[i][2];
}
v0[1][3] = v0[2][1]*v0[3][2] - v0[3][1]*v0[2][2];
v0[2][3] = v0[3][1]*v0[1][2] - v0[1][1]*v0[3][2];
v0[3][3] = v0[1][1]*v0[2][2] - v0[2][1]*v0[1][2];
v1[1][3] = v1[2][1]*v1[3][2] - v1[3][1]*v1[2][2];
v1[2][3] = v1[3][1]*v1[1][2] - v1[1][1]*v1[3][2];
v1[3][3] = v1[1][1]*v1[2][2] - v1[2][1]*v1[1][2];
det = v0[1][1]*v0[2][2]*v0[3][3] + v0[1][2]*v0[2][3]*v0[3][1] + v0[1][3]*v0[2][1]*v0[3][2] - v0[1][3]*v0[2][2]*v0[3][1] - v0[1][2]*v0[2][1]*v0[3][3] - v0[1][1]*v0[2][3]*v0[3][2];
a[1][1] = v0[2][2]*v0[3][3] - v0[2][3]*v0[3][2];
a[1][2] = v0[3][2]*v0[1][3] - v0[3][3]*v0[1][2];
a[1][3] = v0[1][2]*v0[2][3] - v0[1][3]*v0[2][2];
a[2][1] = v0[2][3]*v0[3][1] - v0[2][1]*v0[3][3];
a[2][2] = v0[3][3]*v0[1][1] - v0[3][1]*v0[1][3];
a[2][3] = v0[1][3]*v0[2][1] - v0[1][1]*v0[2][3];
a[3][1] = v0[2][1]*v0[3][2] - v0[2][2]*v0[3][1];
a[3][2] = v0[3][1]*v0[1][2] - v0[3][2]*v0[1][1];
a[3][3] = v0[1][1]*v0[2][2] - v0[1][2]*v0[2][1];
for( i=1 ; i<=3 ; i++ ){
for( j=1 ; j<=3 ; j++ )a[i][j] = a[i][j]/det;
}
n = 0;
for( i=1 ; i<=3 ; i++ ){
for( j=1 ; j<=3 ; j++ ){
m[n] = v1[i][1]*a[1][j] + v1[i][2]*a[2][j] + v1[i][3]*a[3][j];
n++;
}
}
cnv02: for( i=0 ; i<=8 ; i++ ){
if( (as01 > 0) && (mode==0) )m[i] = m[i] * as11 /as01;
para[i+2] = m[i]*65536;
}
for( i=0 ; i<=2 ; i++ ){
para[i+11] = 0;
if( (as11 > 0) && (mode!=0) )para[i+11] = col2[i+1]*( as11 - as01 )/as11*65536;
}
cnv03: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0);
return 0;
}
polygon2(bbuf);
para[0] = (unsigned int)bbuf; para[1] = 0x10c;
para[14]= pp[1]; para[15]= pp[2]; para[16]= pp[3]; para[17]= pp[4];
colmatrix( gwork, para );
goto cnv03;
}
color_mono( gwork, bbuf )
char *gwork, *bbuf;
{
int i, mp[4], pp[6], para[20];
for( i=0 ; i<=8 ; i++ )para[i+2] = 21845;
para[11] = 0; para[12] = 0; para[13] = 0;
mono01: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0 );
return 0;
}
polygon2(bbuf);
para[0] = (unsigned int)bbuf; para[1] = 0x10c;
para[14]= pp[1]; para[15]= pp[2]; para[16]= pp[3]; para[17]= pp[4];
colmatrix( gwork, para );
goto mono01;
}
color_nega( gwork, bbuf )
char *gwork, *bbuf;
{
int i, mp[4], pp[6], para[20];
for( i=0 ; i<=8 ; i++ )para[i+2] = 0;
para[2] = -65536; para[6] = -65536; para[10] = -65536;
para[11] = 2097150; para[12] = 2097150; para[13] = 2097150;
nega01: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0 );
return 0;
}
polygon2(bbuf);
para[0] = (unsigned int)bbuf; para[1] = 0x10c;
para[14]= pp[1]; para[15]= pp[2]; para[16]= pp[3]; para[17]= pp[4];
colmatrix( gwork, para );
goto nega01;
}
color_exg( c1, c2, gwork, bbuf )
int c1, c2;
char *gwork, *bbuf;
{
int i, mp[4], pp[6], para[20];
for( i=0 ; i<=8 ; i++ )para[i+2] = 0;
for( i=0 ; i<3 ; i++ ){
if( i == c1 )para[i*3+c2+2] = 65536;
if( i == c2 )para[i*3+c1+2] = 65536;
if( (i != c1) && (i != c2) )para[i*3+i+2] = 65536;
}
para[11] = 0; para[12] = 0; para[13] = 0;
exg01: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0 );
return 0;
}
polygon2(bbuf);
para[0] = (unsigned int)bbuf; para[1] = 0x10c;
para[14]= pp[1]; para[15]= pp[2]; para[16]= pp[3]; para[17]= pp[4];
colmatrix( gwork, para );
goto exg01;
}
copy(mode,copyvar,ework,gwork,bbuf,pn,dispmode)
int copyvar[];
char *ework, *gwork, *bbuf;
int mode, *pn, *dispmode;
{
int min,max,i,j,wt,maskmode,sw,cx,cy;
int data[2];
char dsp1[] = " MASK( ) CANCEL MIX LENS EXIT";
char dsp2[] = "POLYGON/BOX( ) QUAD-EXPAND";
int mp[4], pp[6], para[20];
/* pp[] = { pn, ax1, ay1, ax2, ay2 } */
command_start(); /* 全画面保存 & data clear */
maskmode = 0;
copy1: windget();
if( mode == 0 )gprint( "<<COPY>>",0,463 );
else gprint( "<<TRANS>>",0,463 );
gprint( dsp1, 0, 463 );
gprint( dsp2, 0, 479 );
for( i = 0 ; i < 2 ; i++ )data[i] = -1;
copy_dsp(copyvar,data,ework);
if( *pn )EGB_color( ework, 0, C_COLOR );
else EGB_color( ework, 0, OFF_COLOR );
gprint( "normal mirror reverse turn zoom expand", 96, 479 );
EGB_color( ework, 0, OFF_COLOR ); /* mask mode display */
gprint( "on rev off", 192, 463 );
EGB_color( ework, 0, C_COLOR );
switch( maskmode ){
case 0: gprint( "off", 192+56, 463 );
break;
case 1: gprint( "on", 192, 463 );
break;
case 2: gprint( "rev", 192+24, 463 );
break;
}
copy2: MOS_disp(1);
mouse( mp, 0, 0, 1 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( cy < 447 )goto copy2;
if( cy < 463 ){
if( cx < 144 )goto copy2;
if( cx < 212 ){ /* mask on 0 */
j = 0;
goto copy3;
}
if( cx < 244 ){ /* mask rev 1 */
j = 1;
goto copy3;
}
if( cx < 288 ){ /* mask off 2 */
j = 2;
goto copy3;
}
if( cx < 352 ){ /* cancel 3 */
j = 3;
goto copy3;
}
if( cx < 416 ){ /* mix */
i = 0; min = 0; max = 256;
goto copy7;
}
if( cx < 472 ){ /* lens */
i = 1; min = 1; max = 8;
goto copy7;
}
if( cx < 512 ){ /* exit 4 */
j = 4;
goto copy3;
}
goto copy2;
}
if( cy < 480 ){
if( cx < 60 ){ /* polygon 5 */
j = 5;
goto copy3;
}
if( cx < 92 ){ /* box 6 */
j = 6;
goto copy3;
}
if( cx < 148 ){ /* copy 7 */
j = 7;
goto copy3;
}
if( cx < 204 ){ /* mirror 8 */
j = 8;
goto copy3;
}
if( cx < 268 ){ /* reverse 9 */
j = 9;
goto copy3;
}
if( cx < 308 ){ /* turn 10 */
j = 10;
goto copy3;
}
if( cx < 348 ){ /* zoom 11 */
j = 11;
goto copy3;
}
if( cx < 416 ){ /* expand 12 */
j = 12;
goto copy3;
}
if( cx < 512 ){ /* quad expand 13 */
j = 13;
goto copy3;
}
goto copy2;
}
goto copy2;
copy3: mouse( mp, 0, 0, 0 );
if( sw > 1 )goto copy2;
MOS_disp(0);
windput();
switch( j ){
case 0: mask_on(1); /* mask on */
maskmode = 1;
break;
case 1: mask_rev(1); /* mask rev */
maskmode = 2;
break;
case 2: vpoly1(); /* mask off */
maskmode = 0;
break;
case 3: backupput(); /* cancel */
polygon2(bbuf);
vpoly1();
if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
break;
case 4: command_end(bbuf); /* exit */
return 0;
case 5: lens_set( copyvar[1] ); /* polygon */
polygon2(bbuf); /* pline clear */
para[0] = (unsigned int)bbuf; /* 画面change */
para[1] = 0x10c;
para[2] = 11; /* mode11:normal change 1990 12 */
puta17( gwork, para );
polygon1( pp, bbuf ); /* polygon */
MOS_disp(0);
if( pp[1] == pp[3] || pp[2] == pp[4] ){ /* 不正 */
polygon2(bbuf);
poly1(bbuf);
*pn = 0;
}
polygon2(bbuf); /* new line clear */
para[2] = 0; /* change */
puta17( gwork, para );
polygon2(bbuf); /* line set */
if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
lens_rest( copyvar[1] );
break;
case 6: lens_set( copyvar[1] ); /* box */
polygon2(bbuf); /* pline clear */
para[0] = (unsigned int)bbuf; /* 画面change */
para[1] = 0x10c;
para[2] = 11; /* mode11:normal change 1990 12 */
puta17( gwork, para );
box( pp, bbuf ); /* box */
MOS_disp(0);
if( pp[1] == pp[3] || pp[2] == pp[4] ){ /* 不正 */
poly1(bbuf);
*pn = 0;
}
para[2] = 0; /* change */
puta17( gwork, para );
polygon2(bbuf); /* line set */
if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
lens_rest( copyvar[1] );
break;
case 7: if( *pn == 0 )break;
lens_set( copyvar[1] ); /* copy */
trans_copy( 0, pp, copyvar[0], gwork, bbuf );
lens_rest( copyvar[1] );
break;
case 8: if( *pn == 0 )break;
lens_set( copyvar[1] ); /* mirror */
trans_copy( 1, pp, copyvar[0], gwork, bbuf );
lens_rest( copyvar[1] );
break;
case 9: if( *pn == 0 )break;
lens_set( copyvar[1] ); /* reverse */
trans_copy( 2, pp, copyvar[0], gwork, bbuf );
lens_rest( copyvar[1] );
break;
case 10: if( *pn == 0 )break; /* turn */
lens_set( copyvar[1] );
turn_copy( pp, copyvar[0], ework, gwork, bbuf, dispmode );
lens_rest( copyvar[1] );
break;
case 11: if( *pn == 0 )break; /* zoom */
lens_set( copyvar[1] );
zoom_copy( pp, copyvar[0], gwork, bbuf, ework );
lens_rest( copyvar[1] );
break;
case 12: if( *pn == 0 )break; /* expand */
lens_set( copyvar[1] );
expand_copy( pp, copyvar[0], gwork, bbuf, ework );
lens_rest( copyvar[1] );
break;
case 13: lens_set( copyvar[1] ); /* quad expand */
quad_copy( copyvar[0], maskmode, gwork, bbuf, ework );
if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
lens_rest( copyvar[1] );
break;
}
goto copy1;
copy7: wt = 20;
copy8: if( sw == 1 )copyvar[i] = copyvar[i] + 1;
if( sw == 2 )copyvar[i] = copyvar[i] - 1;
if( copyvar[i] < min )copyvar[i] = max;
if( copyvar[i] > max )copyvar[i] = min;
copy_dsp(copyvar,data,ework);
vsync_wait( wt );
wt = 2;
MOS_rdpos(&sw,&cx,&cy);
if( sw > 0 )goto copy8;
goto copy2;
}
copy_dsp(copyvar,data,ework)
int copyvar[], data[];
char *ework;
{
int i, x, y;
int point[2][3] = { { 384,463,3 }, /* mix */
{ 456,463,1 } /* lens */
};
char dsp[10];
EGB_color(ework,0,C_COLOR);
for( i = 0 ; i < 2 ; i++ ){
if( data[i] != copyvar[i] ){
x = point[i][0]; y = point[i][1];
MOS_disp(0);
itochar( copyvar[i], point[i][2], dsp );
gprint2( dsp, x, y );
data[i] = copyvar[i];
}
}
return 0;
}
trans_copy( mode, pp, mix, gwork, bbuf )
int mode, pp[], mix;
char *gwork, *bbuf;
{
int xds, yds, sw, cx, cy, mp[4], para[12];
xds = pp[3] - pp[1]; yds = pp[4] - pp[2];
para[0] = (unsigned int)bbuf;
para[1] = 0x10c;
if( mode == 0 ){
para[2] = 1; para[3] = 1; para[4] = pp[1]; para[5] = pp[2];
}
if( mode == 1 ){
para[2] =-1; para[3] = 1; para[4] = pp[3]; para[5] = pp[2];
}
if( mode == 2 ){
para[2] = 1; para[3] =-1; para[4] = pp[1]; para[5] = pp[4];
}
trans1: mouse( mp, xds, yds, 7 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 )return 0;
polygon2(bbuf);
do{ para[6] = cx - ( xds >> 1 );
para[7] = cy - ( yds >> 1 );
para[8] = para[6] + xds;
para[9] = para[7] + yds;
para[10] = mix;
copy17( gwork, para );
MOS_rdpos( &sw, &cx, &cy );
mousesub2( cx, cy );
}while( sw == 1 );
polygon2(bbuf);
goto trans1;
}
turn_copy( pp, mix, ework, gwork, bbuf, dispmode )
int pp[], mix, *dispmode;
char *ework, *gwork, *bbuf;
{
int ax1, ay1, ax2, ay2, sw, cx, cy, xmid, ymid;
int bx1, by1, bx2, by2, xmax, ymax, xmin, ymin, a;
double r, tsin1, tsin2, tcos;
int mp[12], para[16];
short int para2[5];
ax1 = pp[1]; ay1 = pp[2]; ax2 = pp[3]; ay2 = pp[4];
para[0] = (unsigned int)bbuf;
para[1] = 0x10c;
turn1: MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 )return 0;
bx1 = cx; by1 = cy;
if( *dispmode == 0 ){ /* circle display */
para2[0] = cx; para2[1] = cy;
para2[2] = 60; para2[3] = 60;
EGB_ellipse( ework, (char *)para2 );
line_set( cx, cy, cx+60, cy, ework );
}
else {
para2[0] = cx; para2[1] = cy;
para2[2] = 50; para2[3] = 60;
EGB_ellipse( ework, (char *)para2 );
line_set( cx, cy, cx+50, cy, ework );
}
mouse( mp, 0, 0, 2 );
if( *dispmode == 0 ){ /* circle delete */
para2[0] = cx; para2[1] = cy;
para2[2] = 60; para2[3] = 60;
EGB_ellipse( ework, (char *)para2 );
line_set( cx, cy, cx+60, cy, ework );
}
else {
para2[0] = cx; para2[1] = cy;
para2[2] = 50; para2[3] = 60;
EGB_ellipse( ework, (char *)para2 );
line_set( cx, cy, cx+50, cy, ework );
}
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 )goto turn1;
if( cx == bx1 && cy == by1 )goto turn1;
bx2 = cx; by2 = cy;
r = sqrt( (bx1-bx2)*(bx1-bx2) + (by1-by2)*(by1-by2) );
tsin1 = (by2-by1)/r; tsin2 = (by2-by1)/r; tcos = (bx2-bx1)/r;
if( *dispmode ){
tsin1 = tsin1 / 1.2;
tsin2 = tsin2 * 1.2;
}
mp[3] = 0; mp[4] = 0; /* カーソル仮想原点 */
mp[5] = tcos*(ax2-ax1); mp[6] = tsin2*(ax2-ax1);
mp[7] = tcos*(ax2-ax1) - tsin1*(ay2-ay1);
mp[8] = tsin2*(ax2-ax1) + tcos*(ay2-ay1);
mp[9] = -tsin1*(ay2-ay1); mp[10] = tcos*(ay2-ay1);
xmid = mp[7] >> 1; ymid = mp[8] >> 1; /* カーソル用補正 */
mp[3] = mp[3] - xmid; mp[4] = mp[4] - ymid;
mp[5] = mp[5] - xmid; mp[6] = mp[6] - ymid;
mp[7] = mp[7] - xmid; mp[8] = mp[8] - ymid;
mp[9] = mp[9] - xmid; mp[10] = mp[10] - ymid;
turn2: mouse( mp, 0, 0, 14 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 )goto turn1;
bx1 = cx + mp[3]; by1 = cy + mp[4];
bx2 = cx + mp[5]; by2 = cy + mp[6];
xmax = bx1; xmin = bx1; ymax = by1; ymin = by1;
a = tcos*(ax2-ax1) + bx1;
if( xmax < a )xmax = a;
if( xmin > a )xmin = a;
a = tcos*(ax2-ax1) - tsin1*(ay2-ay1) + bx1;
if( xmax < a )xmax = a;
if( xmin > a )xmin = a;
a = -tsin1*(ay2-ay1) + bx1;
if( xmax < a )xmax = a;
if( xmin > a )xmin = a;
a = tsin2*(ax2-ax1) + by1;
if( ymax < a )ymax = a;
if( ymin > a )ymin = a;
a = tsin2*(ax2-ax1) + tcos*(ay2-ay1) + by1;
if( ymax < a )ymax = a;
if( ymin > a )ymin = a;
a = tcos*(ay2-ay1) + by1;
if( ymax < a )ymax = a;
if( ymin > a )ymin = a;
if( xmax > 511 )xmax = 511;
if( xmin < 0 )xmin = 0;
if( ymax > 511 )ymax = 511;
if( ymin < 0 )ymin = 0;
para[2] = tcos*65536; para[3] = tsin1*65536;
para[4] = -tsin2*65536; para[5] = tcos*65536;
para[6] = bx1; para[7] = by1;
para[8] = ax1 * 65536; para[9] = ay1 * 65536;
para[10] = xmin; para[11] = ymin; para[12] = xmax; para[13] = ymax;
para[14] = mix;
polygon2(bbuf);
matrix17( gwork, para );
polygon2(bbuf);
goto turn2;
}
zoom_copy( pp, mix, gwork, bbuf, ework )
int pp[], mix;
char *gwork, *bbuf, *ework;
{
int ax1, ay1, ax2, ay2, sw, cx, cy;
int bx1, by1, bx2, by2, ty1, ty2, ty3, ty4;
int temp;
double ztan;
int mp[4], para[16];
ax1 = pp[1]; ay1 = pp[2]; ax2 = pp[3]; ay2 = pp[4];
para[0] = (unsigned int)bbuf;
para[1] = 0x10c;
ztan = ( (double)(ay2-ay1) )/(ax2-ax1);
zoom1: MOS_disp(1);
mouse( mp , 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 )return 0;
bx1 = cx; by1 = cy;
ty1 = by1 - bx1 * ztan; ty2 = by1 + (511-bx1) * ztan;
ty3 = by1 + bx1 * ztan; ty4 = by1 - (511-bx1) * ztan;
MOS_disp(0);
line_set( 0, ty1, 511, ty2, ework );
line_set( 0, ty3, 511, ty4, ework );
mouse( mp, 0, 0, 4 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
line_set( 0, ty1, 511, ty2, ework );
line_set( 0, ty3, 511, ty4, ework );
if( sw > 1 )goto zoom1;
if( cx == bx1 || cy == by1 )goto zoom1;
bx2 = cx; by2 = cy;
para[2] = ( (double)( ax2 - ax1 ) )*65536/( bx2 - bx1 ); para[3] = 0;
para[4] = 0; para[5] = ( (double)( ay2 - ay1 ) )*65536/( by2 - by1 );
para[6] = bx1; para[7] = by1;
para[8] = ax1 * 65536; para[9] = ay1 * 65536;
para[10] = bx1; para[11] = by1; para[12] = bx2; para[13] = by2;
if( bx1 > bx2 ){
temp = para[10];
para[10] = para[12];
para[12] = temp;
}
if( by1 > by2 ){
temp = para[11];
para[11] = para[13];
para[13] = temp;
}
para[14] = mix;
polygon2(bbuf);
matrix17( gwork, para );
polygon2(bbuf);
goto zoom1;
}
expand_copy( pp, mix, gwork, bbuf, ework)
int pp[], mix;
char *gwork, *bbuf, *ework;
{
int ax1, ay1, ax2, ay2, sw, cx, cy;
int i, bn, xmin, ymin, xmax, ymax, ax, ay, axm, aym, det;
int bx0, by0, bx1, by1, bx2, by2, bx3, by3;
int b[6][2], mp[4], para[18];
ax1 = pp[1]; ay1 = pp[2]; ax2 = pp[3]; ay2 = pp[4];
para[0] = (unsigned int)bbuf;
para[1] = 0x10c;
expnd1: MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 )return 0;
bn = 0; b[0][0] = cx; b[0][1] = cy;
while( bn < 3 ){
mouse( mp, 0, 0, 2 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 ){
if( bn == 0 )goto expnd1;
for( i=1 ; i<=bn ; i++ ){ /* やりなおし */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
goto expnd1;
}
bn++; b[bn][0] = cx; b[bn][1] = cy; /* 次のステップ */
line_set( b[bn-1][0], b[bn-1][1], b[bn][0], b[bn][1], ework );
}
bn = 4; b[4][0] = b[0][0]; b[4][1] = b[0][1]; /* 最後のライン */
line_set( b[3][0], b[3][1], b[4][0], b[4][1], ework );
for( i=1 ; i<=bn ; i++ ){ /* ライン消し */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
if( error_check( square_check( b ) ) )goto expnd1;
xmin = b[0][0]; xmax = b[0][0]; ymin = b[0][1]; ymax = b[0][1];
for( i=0 ; i<4 ; i++ ){ /* 最大,最小 */
if( xmin > b[i][0] )xmin = b[i][0];
if( xmax < b[i][0] )xmax = b[i][0];
if( ymin > b[i][1] )ymin = b[i][1];
if( ymax < b[i][1] )ymax = b[i][1];
}
bx0 = b[0][0]; by0 = b[0][1];
bx1 = b[1][0] - bx0; by1 = b[1][1] - by0;
bx2 = b[2][0] - bx0; by2 = b[2][1] - by0;
bx3 = b[3][0] - bx0; by3 = b[3][1] - by0;
ax = ax2 - ax1; ay = ay2 - ay1;
det = bx1*by3 - bx3*by1; if( det == 0 )goto expnd1;
para[2] = ( ((double)ax)*by3*65536 )/det;
para[3] = -( ((double)ax)*bx3*65536 )/det;
para[4] = -( ((double)ay)*by1*65536 )/det;
para[5] = ( ((double)ay)*bx1*65536 )/det;
axm = para[2]*bx2 + para[3]*by2;
aym = para[4]*bx2 + para[5]*by2;
if( axm == 0 || aym == 0 )goto expnd1;
para[6] = ( (double)( axm - ax*65536 ) )/ax/aym*65536;
para[7] = ( (double)( aym - ay*65536 ) )/ay/axm*65536;
para[8] = bx0; para[9] = by0;
para[10] = ax1 * 65536; para[11] = ay1 * 65536;
para[12] = xmin; para[13] = ymin; para[14] = xmax; para[15] = ymax;
para[16] = mix;
polygon2(bbuf);
expand17( gwork, para );
polygon2(bbuf);
goto expnd1;
}
quad_copy( mix, maskmode, gwork, bbuf, ework)
int mix, maskmode;
char *gwork, *bbuf, *ework;
{
int sw, cx, cy;
int i, n, xmin, ymin, xmax, ymax;
int bx0, by0, bx1, by1, bx2, by2, bx3, by3;
int cx0, cy0, cx1, cy1, cx2, cy2, cx3, cy3;
double det, ax, ay, axm, aym;
int b[6][2], c[6][2], mp[4], para[25], para2[4];
polygon2(bbuf); /* polygon line clear */
quad0: para2[0] = (unsigned int)bbuf; /* 転送画面表示 */
para2[1] = 0x10c;
para2[2] = 11; /* mode11:normal change 1990 12 */
puta17( gwork, para2 );
quad1: MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 ){
puta17( gwork, para2 );
polygon2(bbuf);
return 0;
}
n = 0; b[0][0] = cx; b[0][1] = cy;
while( n < 3 ){
mouse( mp, 0, 0, 2 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 ){
if( n == 0 )goto quad1;
for( i=1 ; i<=n ; i++ ){ /* やりなおし */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
goto quad1;
}
n++; b[n][0] = cx; b[n][1] = cy; /* 次のステップ */
line_set( b[n-1][0], b[n-1][1], b[n][0], b[n][1], ework );
}
n = 4; b[4][0] = b[0][0]; b[4][1] = b[0][1]; /* 最後のライン */
line_set( b[3][0], b[3][1], b[4][0], b[4][1], ework );
for( i=1 ; i<=4 ; i++ ){ /* ライン消し */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
if( error_check( square_check( b ) ) )goto quad1;
bx0 = b[0][0]; by0 = b[0][1];
bx1 = b[1][0] - bx0; by1 = b[1][1] - by0;
bx2 = b[2][0] - bx0; by2 = b[2][1] - by0;
bx3 = b[3][0] - bx0; by3 = b[3][1] - by0;
det = bx1*by3 - bx3*by1; if( det == 0 )goto quad1;
ax = ( by3*bx2 - bx3*by2 )/det;
ay = ( -by1*bx2 + bx1*by2 )/det;
if( (ax == 0) || (ay == 0) )goto quad1;
puta17( gwork, para2 ); /* 元の画面表示 */
quad2: for( i=1 ; i<=4 ; i++ ){ /* 転送元 ライン */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
quad3: if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 ){
for( i=1 ; i<=4 ; i++ ){ /* 転送元ラインdel */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
goto quad0;
}
n = 0; c[0][0] = cx; c[0][1] = cy;
while( n < 3 ){
mouse( mp, 0, 0, 2 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 ){
if( n == 0 )goto quad3;
for( i=1 ; i<=n ; i++ ){ /* やりなおし */
line_set( c[i-1][0], c[i-1][1], c[i][0], c[i][1], ework );
}
goto quad3;
}
n++; c[n][0] = cx; c[n][1] = cy; /* 次のステップ */
line_set( c[n-1][0], c[n-1][1], c[n][0], c[n][1], ework );
}
n = 4; c[4][0] = c[0][0]; c[4][1] = c[0][1]; /* 最後のライン */
line_set( c[3][0], c[3][1], c[4][0], c[4][1], ework );
for( i=1 ; i<=n ; i++ ){ /* ライン消し */
line_set( c[i-1][0], c[i-1][1], c[i][0], c[i][1], ework );
}
if( error_check( square_check( c ) ) )goto quad3;
xmin = c[0][0]; xmax = c[0][0]; ymin = c[0][1]; ymax = c[0][1];
for( i=0 ; i<4 ; i++ ){ /* 最大,最小 */
if( xmin > c[i][0] )xmin = c[i][0];
if( xmax < c[i][0] )xmax = c[i][0];
if( ymin > c[i][1] )ymin = c[i][1];
if( ymax < c[i][1] )ymax = c[i][1];
}
cx0 = c[0][0]; cy0 = c[0][1];
cx1 = c[1][0] - cx0; cy1 = c[1][1] - cy0;
cx2 = c[2][0] - cx0; cy2 = c[2][1] - cy0;
cx3 = c[3][0] - cx0; cy3 = c[3][1] - cy0;
det = cx1*cy3 - cx3*cy1; if( det == 0 )goto quad3;
para[0] = (unsigned int)bbuf;
para[1] = 0x10c;
para[2] = cy3/det*65536; para[3] = -cx3/det*65536;
para[4] = -cy1/det*65536; para[5] = cx1/det*65536;
axm =para[2]*cx2 + para[3]*cy2;
aym =para[4]*cx2 + para[5]*cy2;
if( axm == 0 || aym == 0 )goto quad3;
para[6] = ( axm - 65536 )/aym*65536;
para[7] = ( aym - 65536 )/axm*65536;
para[8] = ( ax - 1 )*65536;
para[9] = ( ay - 1 )*65536;
para[10] = bx1*65536;
para[11] = bx3*65536;
para[12] = by1*65536;
para[13] = by3*65536;
para[14] = cx0;
para[15] = cy0;
para[16] = bx0*65536;
para[17] = by0*65536;
para[18] = xmin; para[19] = ymin; para[20] = xmax; para[21] = ymax;
para[22] = 2;
para[23] = mix;
for( i=1 ; i<=n ; i++ ){ /* ライン消し */
line_set( b[i-1][0], b[i-1][1], b[i][0], b[i][1], ework );
}
quad17( gwork, para );
goto quad2;
}
focus(focusvar,ework,gwork,bbuf)
int focusvar[];
char *ework, *gwork, *bbuf;
{
int min,max,i,j,wt,maskmode,sw,cx,cy;
int data[7];
char dsp1[] = "<<EFFECT>> MASK( ) CANCEL LENS EXIT";
char dsp2[] = "SOFT( ) SHARP( ) DIZA1( ) DIZA2( ) SMOOTH(rate rand )";
int mp[4];
command_start(); /* 全画面保存 & data clear */
maskmode = 0;
focus1: windget();
gprint( dsp1, 0, 463 );
gprint( dsp2, 0, 479 );
for( i = 0 ; i < 7 ; i++ )data[i] = -1;
focus_dsp(focusvar,data,ework);
EGB_color( ework, 0, OFF_COLOR ); /* mask mode display */
gprint( "on rev off", 256, 463 );
EGB_color( ework, 0, C_COLOR );
switch( maskmode ){
case 0: gprint( "off", 256+56, 463 );
break;
case 1: gprint( "on", 256, 463 );
break;
case 2: gprint( "rev", 256+24, 463 );
break;
}
focus2: MOS_disp(1);
mouse( mp, 0, 0, 1 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( cy < 447 )goto focus2;
if( cy < 463 ){
if( cx < 208 )goto focus2;
if( cx < 276 ){ /* mask on 0 */
j = 0;
goto focus3;
}
if( cx < 308 ){ /* mask rev 1 */
j = 1;
goto focus3;
}
if( cx < 352 ){ /* mask off 2 */
j = 2;
goto focus3;
}
if( cx < 416 ){ /* cancel 3 */
j = 3;
goto focus3;
}
if( cx < 472 ){ /* lens */
i = 0; min = 1; max = 8;
goto focus7;
}
if( cx < 512 ){ /* exit 4 */
j = 4;
goto focus3;
}
goto focus2;
}
if( cy < 480 ){
if( cx < 36 ){ /* soft 5 */
j = 5;
goto focus3;
}
if( cx < 80 ){ /* rate */
i = 1; min = 0; max = 256;
goto focus7;
}
if( cx < 132 ){ /* sharp 6 */
j = 6;
goto focus3;
}
if( cx < 172 ){ /* rate */
i = 2; min = 0; max = 256;
goto focus7;
}
if( cx < 228 ){ /* diza1 7 */
j = 7;
goto focus3;
}
if( cx < 256 ){ /* rate */
i = 3; min = 1; max = 8;
goto focus7;
}
if( cx < 308 ){ /* diza2 8 */
j = 8;
goto focus3;
}
if( cx < 336 ){ /* rate */
i = 4; min = 1; max = 8;
goto focus7;
}
if( cx < 396 ){ /* smooth 9 */
j = 9;
goto focus3;
}
if( cx < 460 ){ /* rate */
i = 5; min = 0; max = 32;
goto focus7;
}
if( cx < 512 ){ /* rand# */
i = 6; min = 0; max = 99;
goto focus7;
}
goto focus2;
}
goto focus2;
focus3: mouse( mp, 0, 0, 0 );
if( sw > 1 )goto focus2;
MOS_disp(0);
windput();
switch( j ){
case 0: mask_on(1); /* mask on */
maskmode = 1;
break;
case 1: mask_rev(1); /* mask off */
maskmode = 2;
break;
case 2: vpoly1(); /* mask off */
maskmode = 0;
break;
case 3: backupput(); /* cancel */
if( maskmode == 1 )mask_on(0);
if( maskmode == 2 )mask_rev(0);
break;
case 4: command_end(bbuf); /* exit */
return 0;
case 5: lens_set( focusvar[0] ); /* soft */
focus_set( focusvar[1], gwork, bbuf );
lens_rest( focusvar[0] );
break;
case 6: lens_set( focusvar[0] ); /* sharp */
focus_set( -focusvar[2], gwork, bbuf );
lens_rest( focusvar[0] );
break;
case 7: lens_set( focusvar[0] ); /* diza1 */
diza( 0, focusvar[3], bbuf );
lens_rest( focusvar[0] );
break;
case 8: lens_set( focusvar[0] ); /* diza2 */
diza( 1, focusvar[4], bbuf );
lens_rest( focusvar[0] );
break;
case 9: lens_set( focusvar[0] ); /* smooth */
smooth( focusvar[5], focusvar[6], bbuf );
lens_rest( focusvar[0] );
break;
}
goto focus1;
focus7: wt = 20;
focus8: if( sw == 1 )focusvar[i] = focusvar[i] + 1;
if( sw == 2 )focusvar[i] = focusvar[i] - 1;
if( focusvar[i] < min )focusvar[i] = max;
if( focusvar[i] > max )focusvar[i] = min;
focus_dsp(focusvar,data,ework);
vsync_wait( wt );
wt = 2;
MOS_rdpos(&sw,&cx,&cy);
if( sw > 0 )goto focus8;
goto focus2;
}
focus_dsp(focusvar,data,ework)
int focusvar[], data[];
char *ework;
{
int i, x, y;
int point[][3] = { { 456,463,1 }, /* lens */
{ 40,479,3 },
{ 136,479,3 },
{ 232,479,1 },
{ 312,479,1 },
{ 432,479,2 },
{ 488,479,2 }
};
char dsp[10];
EGB_color(ework,0,C_COLOR);
for( i = 0 ; i < 7 ; i++ ){
if( data[i] != focusvar[i] ){
x = point[i][0]; y = point[i][1];
MOS_disp(0);
itochar( focusvar[i], point[i][2], dsp );
gprint2( dsp, x, y );
data[i] = focusvar[i];
}
}
return 0;
}
focus_set( rate, gwork, bbuf )
int rate;
char *gwork, *bbuf;
{
int i;
int mp[4], pp[6], para[16];
para[0] = (unsigned int)bbuf;
para[1] = 0x10c;
for( i=0 ; i<=8 ; i++ )para[i+2] = ( rate >> 3 );
para[6] = 256 - para[2]*8;
foc01: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0 );
return 0;
}
polygon2(bbuf);
para[11] = pp[1]; para[12] = pp[2];
para[13] = pp[3]; para[14] = pp[4];
focus17( gwork, para );
goto foc01;
}
/* 新しいrand()が合わなくなったんで自家製に切り換え 1993 3/6 */
my_rand()
{
static unsigned int next = 1 ;
next = next * 1103515245 + 12345 ;
return (unsigned int)( next / 65536 ) % 32768 ;
}
diza( mode, rate, bbuf )
int mode, rate;
char *bbuf;
{
int i, j, n, data, b, r, g, div, rnd;
int mp[4], pp[6];
div = 32768/(rate*2+1);
diza1: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0 );
return 0;
}
polygon2(bbuf);
for( i=pp[2] ; i<=pp[4] ; i++ ){
for( j=pp[1] ; j<=pp[3] ; j++ ){
n = ( i << 10 ) + ( j << 1 );
if( ( peekw( (unsigned int)n, 0x10c ) < 0x8000 ) && ( WORD( bbuf + n ) >= 0x8000 ) ){
data = WORD( bbuf + n );
b = data & 0x1f;
r = (data & 0x3e0) >> 5;
g = (data & 0x7c00) >> 10;
if( mode == 0 ){
b = b + my_rand()/div - rate;
r = r + my_rand()/div - rate;
g = g + my_rand()/div - rate;
}
else {
rnd = my_rand()/div - rate;
b = b + rnd;
r = r + rnd;
g = g + rnd;
}
if( b < 0 )b = 0;
if( b > 0x1f )b =0x1f;
if( r < 0 )r = 0;
if( r > 0x1f )r =0x1f;
if( g < 0 )g = 0;
if( g > 0x1f )g =0x1f;
pokew( (unsigned int)n, 0x10c, b+(r << 5)+(g << 10) );
}
}
}
goto diza1;
}
smooth( rate, rnd, bbuf )
int rate, rnd;
char *bbuf;
{
int ax1, ay1, ax2, ay2, a, b, c, d, cmp, start, mid, fine, mode, r, s, x, y, vadd;
int k0, k1, k2;
int mp[4], pp[6];
smoo1: MOS_disp(1);
if( polygon1( pp, bbuf ) ){
mouse( mp, 0, 0, 0 );
return 0;
}
polygon2(bbuf);
ax1 = pp[1]; ay1 = pp[2]; ax2 = pp[3]; ay2 = pp[4];
s = 32 - rate; /* sharp rate */
r = rnd;
for( y=ay1+1 ; y<=ay2-1 ; y++ ){
vadd = y*1024; mode = 0;
for( x=ax1+1 ; x<=ax2-1 ; x++ ){
a=WORD(bbuf+vadd+x*2);
b=WORD(bbuf+vadd+x*2+1024);
c=WORD(bbuf+vadd+x*2+2);
d=WORD(bbuf+vadd+x*2-1022);
cmp = cmpdata( a, b, s );
if( (mode == 0) && cmp ){
mode = 1;
start = x;
k0 = 0;
}
if( (mode == 1) && (cmp == 0) )mode = 0;
if( (mode == 2) && (cmpdata( a, d, s ) == 0) ){
mode = 0;
fine = x;
smooth1( start, mid, fine, y, r, bbuf );
x = mid;
}
if( mode == 1 ){
k1 = katamuki( x, y, bbuf );
if( cmpdata(a,c,s) ){
if( (k1 <= k0) && (k1 < 0) ){
k2 = katamuki( x+1, y, bbuf );
if( (k1 <= k2) || (cmpdata(b,c,12) == 0) ){
mode = 2;
mid = x;
}
}
}
k0 = k1;
}
if( (mode == 2) && (cmpdata( c, d, s ) == 0) ){
mode = 0;
fine = x;
smooth1( start, mid, fine, y, r, bbuf );
x = mid;
}
}
}
for( y=ay1+1 ; y<=ay2-1 ; y++ ){
vadd = y*1024; mode = 0;
for( x=ax2-1 ; x>=ax1+1 ; x-- ){
a=WORD(bbuf+vadd+x*2);
b=WORD(bbuf+vadd+x*2+1024);
c=WORD(bbuf+vadd+x*2-2);
d=WORD(bbuf+vadd+x*2-1026);
cmp = cmpdata( a, b, s );
if( (mode == 0) && cmp ){
mode = 1;
start = x;
k0 = 0;
}
if( (mode == 1) && (cmp == 0) )mode = 0;
if( (mode == 2) && (cmpdata( a, d, s ) == 0) ){
mode = 0;
fine = x;
smooth2( start, mid, fine, y, r, bbuf );
x = mid;
}
if( mode == 1 ){
k1 = katamuki( x, y, bbuf );
if( cmpdata(a,c,s) ){
if( (k1 >= k0) && (k1 > 0) ){
k2 = katamuki( x-1, y, bbuf );
if( (k1 >= k2) || (cmpdata(b,c,12) == 0) ){
mode = 2;
mid = x;
}
}
}
k0 = k1;
}
if( (mode == 2) && (cmpdata( c, d, s ) == 0) ){
mode = 0;
fine = x;
smooth2( start, mid, fine, y, r, bbuf );
x = mid;
}
}
}
for( x=ax1+1 ; x<=ax2-1 ; x++ ){
vadd = x*2; mode = 0;
for( y=ay1+1 ; y<=ay2-1 ; y++ ){
a=WORD(bbuf+vadd+y*1024);
b=WORD(bbuf+vadd+y*1024+2);
c=WORD(bbuf+vadd+y*1024+1024);
d=WORD(bbuf+vadd+y*1024+1022);
cmp = cmpdata( a, b, s );
if( (mode == 0) && cmp ){
mode = 1;
start = y;
k0 = 0;
}
if( (mode == 1) && (cmp == 0) )mode = 0;
if( (mode == 2) && (cmpdata( a, d, s ) == 0) ){
mode = 0;
fine = y;
smooth3( start, mid, fine, x, r, bbuf );
y = mid;
}
if( mode == 1 ){
k1 = katamuki( x, y, bbuf );
if( cmpdata(a,c,s) ){
if( (k1 <= k0) && (k1 < 0) ){
k2 = katamuki( x, y+1, bbuf );
if( (k1 <= k2) || (cmpdata(b,c,12) == 0) ){
mode = 2;
mid = y;
}
}
}
k0 = k1;
}
if( (mode == 2) && (cmpdata( c, d, s ) == 0) ){
mode = 0;
fine = y;
smooth3( start, mid, fine, x, r, bbuf );
y = mid;
}
}
}
for( x=ax2-1 ; x>=ax1+1 ; x-- ){
vadd = x*2; mode = 0;
for( y=ay1+1 ; y<=ay2-1 ; y++ ){
a=WORD(bbuf+vadd+y*1024);
b=WORD(bbuf+vadd+y*1024-2);
c=WORD(bbuf+vadd+y*1024+1024);
d=WORD(bbuf+vadd+y*1024+1026);
cmp = cmpdata( a, b, s );
if( (mode == 0) && cmp ){
mode = 1;
start = y;
k0 = 0;
}
if( (mode == 1) && (cmp == 0) )mode = 0;
if( (mode == 2) && (cmpdata( a, d, s ) == 0) ){
mode = 0;
fine = y;
smooth4( start, mid, fine, x, r, bbuf );
y = mid;
}
if( mode == 1 ){
k1 = katamuki( x, y, bbuf );
if( cmpdata(a,c,s) ){
if( (k1 >= k0) && (k1 > 0) ){
k2 = katamuki( x, y+1, bbuf );
if( (k1 >= k2) || (cmpdata(b,c,12) == 0) ){
mode = 2;
mid = y;
}
}
}
k0 = k1;
}
if( (mode == 2) && (cmpdata( c, d, s ) == 0) ){
mode = 0;
fine = y;
smooth4( start, mid, fine, x, r, bbuf );
y = mid;
}
}
}
goto smoo1;
}
katamuki( x, y, bbuf ) /* return=(karamuki + or 0 or -) s=rate */
int x, y;
char *bbuf;
{
int p[3][3];
int vadd, ck;
vadd = y*1024; ck = 0;
if( (vadd+x*2-1026 < 0) || (vadd+x*2+1026 > 524286) )return 0;
p[0][0]=WORD(bbuf+vadd+x*2-1026);
p[0][1]=WORD(bbuf+vadd+x*2-1024);
p[0][2]=WORD(bbuf+vadd+x*2-1022);
p[1][0]=WORD(bbuf+vadd+x*2-2);
p[1][1]=WORD(bbuf+vadd+x*2);
p[1][2]=WORD(bbuf+vadd+x*2+2);
p[2][0]=WORD(bbuf+vadd+x*2+1022);
p[2][1]=WORD(bbuf+vadd+x*2+1024);
p[2][2]=WORD(bbuf+vadd+x*2+1026);
ck = ck - kata_s( p[0][0], p[1][1] );
ck = ck - kata_s( p[0][1], p[1][2] );
ck = ck - kata_s( p[1][0], p[2][1] );
ck = ck - kata_s( p[1][1], p[2][2] );
ck = ck + kata_s( p[0][1], p[1][0] );
ck = ck + kata_s( p[0][2], p[1][1] );
ck = ck + kata_s( p[1][1], p[2][0] );
ck = ck + kata_s( p[1][2], p[2][1] );
return ck;
}
kata_s( a, b ) /* total abs(sub) */
int a, b;
{
int data1, data2, subd, add;
data1 = a & 0x1f; data2 = b & 0x1f;
subd = data2 - data1; if( subd < 0 )subd = -subd;
add = subd;
data1 = (a >> 5) & 0x1f; data2 = (b >> 5) & 0x1f;
subd = data2 - data1; if( subd < 0 )subd = -subd;
add = add + subd;
data1 = (a >> 10) & 0x1f; data2 = (b >> 10) & 0x1f;
subd = data2 - data1; if( subd < 0 )subd = -subd;
add = add + subd;
return add;
}
cmpdata( a, b, rate )
int a, b, rate;
{
int data1, data2, subd;
data1 = a & 0x1f; data2 = b & 0x1f;
subd = data2 - data1; if( subd < 0 )subd = -subd;
if( subd > rate )return 1;
data1 = (a >> 5) & 0x1f; data2 = (b >> 5) & 0x1f;
subd = data2 - data1; if( subd < 0 )subd = -subd;
if( subd > rate )return 1;
data1 = (a >> 10) & 0x1f; data2 = (b >> 10) & 0x1f;
subd = data2 - data1; if( subd < 0 )subd = -subd;
if( subd > rate )return 1;
return 0;
}
smooth1( st, md, fn, y, r, bbuf ) /* r=random( 0-256 ) */
int st, md, fn, y, r;
char *bbuf;
{
int x1, x2, x3;
int i, n, top, rate, a, b, c;
x1 = ( st + md ) >> 1;
x2 = md;
x3 = ( md + fn + 1 ) >> 1;
top = y*1024;
if( x1 == x2 )goto smoo1;
rate = 128/(x2-x1+1);
n = 1;
for( i=x1 ; i<=x2-1 ; i++ ){
a = WORD( bbuf+top+i*2+1024 );
b = peekw( top+i*2, 0x10c );
if( (WORD( bbuf+top+i*2 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, n*rate, r );
pokew( top+i*2, 0x10c, c );
}
n++;
}
if( x2 == x3 )goto smoo2;
smoo1: if( x2 == x3 )return 0;
rate = 128/(x3-x2+1);
n = 1;
for( i=x2+1 ; i<=x3 ; i++ ){
a = WORD( bbuf+top+i*2-1024 );
b = peekw( top+i*2, 0x10c );
if( (WORD( bbuf+top+i*2 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, (128 - n*rate), r );
pokew( top+i*2, 0x10c, c );
}
n++;
}
smoo2: a = peekw( top+x2*2-2, 0x10c );
b = peekw( top+x2*2+2, 0x10c );
if( (WORD( bbuf+top+x2*2 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, 128, r );
pokew( top+x2*2, 0x10c, c );
}
return 0;
}
smooth2( st, md, fn, y, r, bbuf ) /* r=random( 0-256 ) */
int st, md, fn, y, r;
char *bbuf;
{
int x1, x2, x3;
int i, n, top, rate, a, b, c;
x1 = ( st + md + 1 ) >> 1;
x2 = md;
x3 = ( md + fn ) >> 1;
top = y*1024;
if( x1 == x2 )goto smoo1;
rate = 128/(x1-x2+1);
n = 1;
for( i=x1 ; i>=x2+1 ; i-- ){
a = WORD( bbuf+top+i*2+1024 );
b = peekw( top+i*2, 0x10c );
if( (WORD( bbuf+top+i*2 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, n*rate, r );
pokew( top+i*2, 0x10c, c );
}
n++;
}
if( x2 == x3 )goto smoo2;
smoo1: if( x2 == x3 )return 0;
rate = 128/(x2-x3+1);
n = 1;
for( i=x2-1 ; i>=x3 ; i-- ){
a = WORD( bbuf+top+i*2-1024 );
b = peekw( top+i*2, 0x10c );
if( (WORD( bbuf+top+i*2 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, (128 - n*rate), r );
pokew( top+i*2, 0x10c, c );
}
n++;
}
smoo2: a = peekw( top+x2*2+2, 0x10c );
b = peekw( top+x2*2-2, 0x10c );
if( (WORD( bbuf+top+x2*2 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, 128, r );
pokew( top+x2*2, 0x10c, c );
}
return 0;
}
smooth3( st, md, fn, x, r, bbuf )
int st, md, fn, x, r;
char *bbuf;
{
int y1, y2, y3;
int i, n, top, rate, a, b, c;
y1 = ( st + md ) >> 1;
y2 = md;
y3 = ( md + fn ) >> 1;
top = x*2;
if( y1 == y2 )goto smoo1;
rate = 128/(y2-y1+1);
n = 1;
for( i=y1 ; i<=y2-1 ; i++ ){
a = WORD( bbuf+top+i*1024+2 );
b = peekw( top+i*1024, 0x10c );
if( (WORD( bbuf+top+i*1024 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, n*rate, r );
pokew( top+i*1024, 0x10c, c );
}
n++;
}
if( y2 == y3 )goto smoo2;
smoo1: if( y2 == y3 )return 0;
rate = 128/(y3-y2+1);
n = 1;
for( i=y2+1 ; i<=y3 ; i++ ){
a = WORD( bbuf+top+i*1024-2 );
b = peekw( top+i*1024, 0x10c );
if( (WORD( bbuf+top+i*1024 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, (128 - n*rate), r );
pokew( top+i*1024, 0x10c, c );
}
n++;
}
smoo2: a = peekw( top+y2*1024+1024, 0x10c );
b = peekw( top+y2*1024-1024, 0x10c );
if( (WORD( bbuf+top+y2*1024 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, 128, r );
pokew( top+y2*1024, 0x10c, c );
}
return 0;
}
smooth4( st, md, fn, x, r, bbuf )
int st, md, fn, x, r;
char *bbuf;
{
int y1, y2, y3;
int i, n, top, rate, a, b, c;
y1 = ( st + md ) >> 1;
y2 = md;
y3 = ( md + fn ) >> 1;
top = x*2;
if( y1 == y2 )goto smoo1;
rate = 128/(y2-y1+1);
n = 1;
for( i=y1 ; i<=y2-1 ; i++ ){
a = WORD( bbuf+top+i*1024-2 );
b = peekw( top+i*1024, 0x10c );
if( (WORD( bbuf+top+i*1024 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, n*rate, r );
pokew( top+i*1024, 0x10c, c );
}
n++;
}
if( y2 == y3 )goto smoo2;
smoo1: if( y2 == y3 )return 0;
rate = 128/(y3-y2+1);
n = 1;
for( i=y2+1 ; i<=y3 ; i++ ){
a = WORD( bbuf+top+i*1024+2 );
b = peekw( top+i*1024, 0x10c );
if( (WORD( bbuf+top+i*1024 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, (128 - n*rate), r );
pokew( top+i*1024, 0x10c, c );
}
n++;
}
smoo2: a = peekw( top+y2*1024+1024, 0x10c );
b = peekw( top+y2*1024-1024, 0x10c );
if( (WORD( bbuf+top+y2*1024 ) & 0x8000) && (b < 0x8000) ){
c = mix( a, b, 128, r );
pokew( top+y2*1024, 0x10c, c );
}
return 0;
}
mix( a, b, rate, r ) /* r = random rate ( 0-256 ) ( rate +-r ) */
int a, b, rate, r;
{
int div, rate1, data, data1, data2, add;
div = 32768/(r*2 + 1);
rate1 = rate + my_rand()/div - r;
if( rate1 < 0 )rate1 = 0;
if( rate1 > 256 )rate1 = 256;
data1 = a & 0x1f; data2 = b & 0x1f;
add = ( data1*rate1 + data2*(256-rate1) + 0x80 ) >> 8;
data = add;
rate1 = rate + my_rand()/div - r;
if( rate1 < 0 )rate1 = 0;
if( rate1 > 256 )rate1 = 256;
data1 = (a >> 5) & 0x1f; data2 = (b >> 5) & 0x1f;
add = ( data1*rate1 + data2*(256-rate1) + 0x80 ) >> 8;
data = data + ( add << 5 );
rate1 = rate + my_rand()/div - r;
if( rate1 < 0 )rate1 = 0;
if( rate1 > 256 )rate1 = 256;
data1 = (a >> 10) & 0x1f; data2 = (b >> 10) & 0x1f;
add = ( data1*rate1 + data2*(256-rate1) + 0x80 ) >> 8;
data = data + ( add << 10 );
return data;
}
zoom( zvar, ework, gwork, bbuf )
int zvar[];
char *ework, *gwork, *bbuf;
{
int min,max,i,j,wt,sw,cx,cy;
int data[9], mp[4], para[20];
char dsp1[] = "<<HG-ZOOM>> HG-ZOOM SHARP CANCEL EXIT";
char dsp2[] = "SOURCE( , )-( , ) → DESTINATINO( , )-( , )";
command_start(); /* 全画面保存 & data clear */
zoom01: windget();
gprint( dsp1, 0, 463 );
gprint( dsp2, 0, 479 );
for( i = 0 ; i < 9 ; i++ )data[i] = -1000;
zoom_dsp( zvar, data, ework );
zoom02: MOS_disp(1);
mouse( mp, 0, 0, 1 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( cy < 447 )goto zoom02;
if( cy < 463 ){
if( cx < 96 )goto zoom02;
if( cx < 168 ){ /* zoom 0 */
j = 0;
goto zoom03;
}
if( cx < 248 ){ /* sharp */
i = 8; min = -256; max = 256;
goto zoom07;
}
if( cx < 408 )goto zoom02; /* nothing */
if( cx < 472 ){
j = 1;
goto zoom03;
}
if( cx < 512 ){ /* exit -> 2 */
j = 2;
goto zoom03;
}
goto zoom02;
}
if( cy < 480 ){
if( cx < 52 ){ /* source -> 3 */
j = 3;
goto zoom03;
}
if( cx < 88 ){ /* xs1 */
i = 0; min = 0; max = 511;
goto zoom07;
}
if( cx < 132 ){ /* ys1 */
i = 1; min = 0; max = 511;
goto zoom07;
}
if( cx < 176 ){ /* xs2 */
i = 2; min = 0; max = 511;
goto zoom07;
}
if( cx < 232 ){ /* ys2 */
i = 3; min = 0; max = 511;
goto zoom07;
}
if( cx < 340 ){ /* destination -> 4 */
j = 4;
goto zoom03;
}
if( cx < 376 ){ /* xd1 */
i = 4; min = 0; max = 511;
goto zoom07;
}
if( cx < 420 ){ /* yd1 */
i = 5; min = 0; max = 511;
goto zoom07;
}
if( cx < 464 ){ /* xd2 */
i = 6; min = 0; max = 511;
goto zoom07;
}
if( cx < 512 ){ /* yd2 */
i = 7; min = 0; max = 511;
goto zoom07;
}
goto zoom02;
}
goto zoom02;
zoom03: mouse( mp, 0, 0, 0 );
if( sw > 1 )goto zoom02;
MOS_disp(0);
windput();
switch( j ){
case 0: zooming( zvar, bbuf ); /* ZOOM */
break;
case 1: backupput(); /* cancel */
break;
case 2: return 0;
case 3: lens_set( 1 ); /* source coodrna. */
para[0] = (unsigned int)bbuf; /* 画面change */
para[1] = 0x10c;
para[2] = 0;
puta17( gwork, para );
zoom_coodr( zvar );
MOS_disp(0);
puta17( gwork, para );
lens_rest( 1 );
break;
case 4: lens_set( 1 ); /* desti. coodrna. */
zoom_coodr( zvar + 4 );
lens_rest( 1 );
break;
}
goto zoom01;
zoom07: wt = 20;
zoom08: if( sw == 1 )zvar[i] = zvar[i] + 1;
if( sw == 2 )zvar[i] = zvar[i] - 1;
if( zvar[i] < min )zvar[i] = max;
if( zvar[i] > max )zvar[i] = min;
zoom_dsp( zvar, data, ework );
vsync_wait( wt );
wt = 2;
MOS_rdpos(&sw,&cx,&cy);
if( sw > 0 )goto zoom08;
goto zoom02;
}
zoom_dsp( zvar, data, ework )
int zvar[], data[];
char *ework;
{
int i;
int point[][3] = { { 56,479,3 },
{ 96,479,3 },
{ 144,479,3 },
{ 184,479,3 },
{ 344,479,3 },
{ 384,479,3 },
{ 432,479,3 },
{ 472,479,3 },
{ 216,463,3 }
};
char dsp[6];
for( i = 0 ; i < 9 ; i++ ){
if( data[i] != zvar[i] ){
MOS_disp(0);
if( i == 8 )gprint2(" ", point[i][0], point[i][1]);
itochar( zvar[i], point[i][2], dsp );
EGB_color(ework,0,C_COLOR);
gprint2( dsp, point[i][0], point[i][1] );
data[i] = zvar[i];
}
}
return 0;
}
zoom_coodr( var )
int var[];
{
int sw, cx, cy, temp;
int mp[4];
zoom1: MOS_disp(1);
mouse( mp, 0, 0, 0 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
MOS_disp(0);
if( sw > 1 )goto zoom2;
var[0] = cx; var[1] = cy;
mouse( mp, 0, 0, 4 );
sw = mp[0]; cx = mp[1]; cy = mp[2];
if( sw > 1 )goto zoom1;
if( cx == var[0] || cy == var[1] )return 0;
var[2] = cx; var[3] = cy;
zoom2: if( var[0] > var[2] ){
temp = var[0]; var[0] = var[2]; var[2] = temp;
}
if( var[1] > var[3] ){
temp = var[1]; var[1] = var[3]; var[3] = temp;
}
return 0;
}
zooming( var, bbuf )
int var[];
char *bbuf;
{
int ax1, ay1, ax2, ay2, ax, ay, axd, ayd;
int bx1, by1, bx2, by2, x, y, vadd, xds, yds;
int data1, data2, data3, data4;
char *dadd;
int temp, i, j, b, r, g, s, p[3][4];
/* 座標初期設定 */
if( var[0] < var[2] ){ ax1 = var[0]; ax2 = var[2]; }
else { ax1 = var[2]; ax2 = var[0]; }
if( var[1] < var[3] ){ ay1 = var[1]; ay2 = var[3]; }
else { ay1 = var[3]; ay2 = var[1]; }
if( var[4] < var[6] ){ bx1 = var[4]; bx2 = var[6]; }
else { bx1 = var[6]; bx2 = var[4]; }
if( var[5] < var[7] ){ by1 = var[5]; by2 = var[7]; }
else { by1 = var[7]; by2 = var[5]; }
if( ( bx1 == bx2 ) || ( by1 == by2 ) ){ /* 座標error */
return 0;
}
s = var[8]; /* sharp rate */
ax1 = ax1 << 16; ay1 = ay1 << 16;
ax2 = ax2 << 16; ay2 = ay2 << 16; /* 仮想座標 16bit.16bit */
axd = ( ax2 - ax1 )/( bx2 - bx1 ); /* ovre sampling rate */
ayd = ( ay2 - ay1 )/( by2 - by1 );
ay = ay1; /* ay: 可変 samplin y座標 */
zoom1: for( y=by1 ; y<=by2 ; y++ ){ /* y-loop */
ax = ax1; /* ax: 可変 sampling x座標 */
dadd = bbuf + (ay >> 16)*1024 + (ax >> 16)*2; /*data add*/
vadd = y*1024 + bx1*2; /*v-ram addr*/
yds = ( ay >> 8 ) & 0xff; /* over smp. Y-少数部分 */
for( i=0 ; i<3 ; i++ ){ /* x-loop 初期data set */
if( ay > 0xffff ){
for( j=0 ; j<4 ; j++ ){ /* y座標 > 0 */
data1 = WORD( dadd+(j-1)*2-1024 );
data1 = ( ( data1 >> (i*5) ) & 0x1f ) << 3;
data2 = WORD( dadd+(j-1)*2 );
data2 = ( ( data2 >> (i*5) ) & 0x1f ) << 3;
data3 = WORD( dadd+(j-1)*2+1024 );
data3 = ( ( data3 >> (i*5) ) & 0x1f ) << 3;
data4 = WORD( dadd+(j-1)*2+2048 );
data4 = ( ( data4 >> (i*5) ) & 0x1f ) << 3;
p[i][j] = smp17(yds,data1,data2,data3,data4,s);
}
}
else {
for( j=0 ; j<4 ; j++ ){ /* y座標 = 0 */
data1 = WORD( dadd+(j-1)*2 );
data1 = ( ( data1 >> (i*5) ) & 0x1f ) << 3;
data2 = data1;
data3 = WORD( dadd+(j-1)*2+1024 );
data3 = ( ( data3 >> (i*5) ) & 0x1f ) << 3;
data4 = WORD( dadd+(j-1)*2+2048 );
data4 = ( ( data4 >> (i*5) ) & 0x1f ) << 3;
p[i][j] = smp17(yds,data1,data2,data3,data4,s);
}
}
if( ax < 0x10000 )p[0][j] = p[1][j]; /* x座標 = 0 */
}
for( x=bx1 ; x<=bx2 ; x++ ){ /* x-loop */
if( x > 511 )break; /* はみ出した場合次のy-loop */
xds = ( ax >> 8 ) & 0xff; /* over smp. X-少数部分 */
b = smp17( xds, p[0][0], p[0][1], p[0][2], p[0][3],s );
r = smp17( xds, p[1][0], p[1][1], p[1][2], p[1][3],s );
g = smp17( xds, p[2][0], p[2][1], p[2][2], p[2][3],s );
if( b < 0 )b=0;
if( b > 255 )b=255;
if( r < 0 )r=0;
if( r > 255 )r=255;
if( g < 0 )g=0;
if( g > 255 )g=255;
pokew( vadd, 0x10c, (b>>3)+((r<<2)&0x3e0)+((g<<7)&0x7c00) );
vadd = vadd + 2; /* inc data */
temp = ax >> 16; ax = ax + axd;
while( temp < ( ax >> 16 ) ){ /* 整数部分変化有り */
dadd = dadd + 2;
for( i=0 ; i<3 ; i++ ){
p[i][0] = p[i][1];
p[i][1] = p[i][2];
p[i][2] = p[i][3];
if( ay > 0xffff ){ /* y > 0 */
data1 = WORD( dadd+4-1024 );
data1 = ((data1 >> (i*5)) & 0x1f) << 3;
data2 = WORD( dadd+4 );
data2 = ((data2 >> (i*5)) & 0x1f) << 3;
data3 = WORD( dadd+4+1024 );
data3 = ((data3 >> (i*5)) & 0x1f) << 3;
data4 = WORD( dadd+4+2048 );
data4 = ((data4 >> (i*5)) & 0x1f) << 3;
p[i][3] = smp17(yds,data1,data2,data3,data4,s);
}
else { /* y = 0 */
data1 = WORD( dadd+4 );
data1 = ((data1 >> (i*5)) & 0x1f) << 3;
data2 = data1;
data3 = WORD( dadd+4+1024 );
data3 = ((data3 >> (i*5)) & 0x1f) << 3;
data4 = WORD( dadd+4+2048 );
data4 = ((data4 >> (i*5)) & 0x1f) << 3;
p[i][3] = smp17(yds,data1,data2,data3,data4,s);
}
}
temp++;
}
}
ay = ay + ayd;
}
return 0;
}
line_set( x1, y1, x2, y2, ework )
int x1, y1, x2, y2;
char *ework;
{
char para[32];
EGB_color( ework, 0, C_COLOR );
EGB_writeMode( ework, 4 ); /* XOR */
EGB_paintMode( ework, 0x22 );
WORD( para+0 ) = 2;
WORD( para+2 ) = x1;
WORD( para+4 ) = y1;
WORD( para+6 ) = x2;
WORD( para+8 ) = y2;
EGB_unConnect( ework, para );
return 0;
}